import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import set from '@feidao/web/atom/browser/global/set';
import get from '@feidao/web/atom/browser/global/get';

export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	console.log('one_check');
	const curr = args[0].currentTarget as HTMLInputElement;
	const one_checks = Array.from(fd.data.node.querySelectorAll('[data-feidao-id="one_check"]'));
	const all_check = fd.data.node.querySelector("#all_check") as HTMLInputElement;
	const check_all = !(one_checks.some((one: HTMLInputElement) => {
		return (one.checked === false);
	}));
	all_check.checked = check_all;
	const _id = curr.dataset.feidaoDel;
	const del_data = get("del_data") || [];
	if (curr.checked) {
		del_data.push({ _id });
	} else {
		del_data.forEach((item: any, i: number) => {
			if (item._id == _id) {
				del_data.splice(i, 1);
			}
		});
	}
	set("del_data", del_data);
}
